PastAttacks_Country_All*AgeMean +
PastAttacks_Country_All*StudentPop +
PastAttacks_Country_All*US +
CasualtiesLess10 + Casualties10to100 + Casualties100plus +
Exp + NatExp +
ProbSample +
StudentPop +
Outgroup + Rally +
US +
FemaleP +
AgeMean,
random = ~ 1 | ID_R/ID_ES_Unique, # three-level model
data = df)
m2_past_3_mods
# ... Model 2: Attacks in the West, no time restriction.
m2_past_4_mods <- rma.mv(d, var_d,
mods = ~ PastAttacks_West_All*FemaleP +
PastAttacks_West_All*AgeMean +
PastAttacks_West_All*StudentPop +
PastAttacks_West_All*US +
CasualtiesLess10 + Casualties10to100 + Casualties100plus +
Exp + NatExp +
ProbSample +
StudentPop +
Outgroup + Rally +
US +
FemaleP +
AgeMean,
random = ~ 1 | ID_R/ID_ES_Unique, # three-level model
data = df)
m2_past_4_mods
# Create the table
cm <- c("StudyYear"     = "Year of study",
"PastAttacks_Country_5yr" = "Same country in previous 5 years",
"PastAttacks_West_5yr" = "All Western countries in previous 5 years",
"PastAttacks_Country_All" = "Same country in all previous years",
"PastAttacks_West_All" = "All Western countries in all previous years",
"FemaleP"       = "Percentage of Female Respondents",
"AgeMean"       = "Mean Age of Respondents",
"CasualtiesLess101"  = "Fatalities: $<$10",
"Casualties10to1001" = "Fatalities: 10–100",
"Casualties100plus1" = "Fatalities: $>$100",
"Exp1"          = "Randomized experiment",
"NatExp1"       = "Natural experiment",
"ProbSample1"   = "Probability sample",
"StudentPop"    = "Student sample",
"Outgroup"      = "Outgroup hostility",
"Rally"         = "Rally tendencies",
"US"            = "US study",
"StudyYear:FemaleP" = "Year of Study * Female share",
"StudyYear:AgeMean" = "Year of Study  * Mean age",
"StudyYear:StudentPop" = "Year of Study  * Student population",
"StudyYear:US" = "Year of Study  * US study",
"PastAttacks_Country_5yr:FemaleP" = "Past attacks * Female share",
"PastAttacks_Country_5yr:AgeMean" = "Past attacks * Mean age",
"PastAttacks_Country_5yr:StudentPop" = "Past attacks * Student population",
"PastAttacks_Country_5yr:US" = "Past attacks *  US study",
"PastAttacks_West_5yr:FemaleP" = "Past attacks * Female share",
"PastAttacks_West_5yr:AgeMean" = "Past attacks * Mean age",
"PastAttacks_West_5yr:StudentPop" = "Past attacks * Student population",
"PastAttacks_West_5yr:US" = "Past attacks *  US study",
"PastAttacks_Country_All:FemaleP" = "Past attacks * Female share",
"PastAttacks_Country_All:AgeMean" = "Past attacks * Mean age",
"PastAttacks_Country_All:StudentPop" = "Past attacks * Student population",
"PastAttacks_Country_All:US" = "Past attacks *  US study",
"PastAttacks_West_All:FemaleP" = "Past attacks * Female share",
"PastAttacks_West_All:AgeMean" = "Past attacks * Mean age",
"PastAttacks_West_All:StudentPop" = "Past attacks * Student population",
"PastAttacks_West_All:US" = "Past attacks *  US study",
"intrcpt"       = "Constant")
modelsummary(models,
coef_map = cm,
stars = c("*" = .05, "**" = .01, "***" = .001),
fmt = 3,
gof_omit = 'IC|Log|Adj|AIC|BIC|RMSE',
escape = FALSE,
output = "latex_tabular")
m2_past_4_mods
# Step 1: Create a named list of models
models <- list(
"(1)" = m2_mods,
"(2)" = m2_past_1_mods,
"(3)" = m2_past_2_mods,
"(4)" = m2_past_3_mods,
"(5)" = m2_past_4_mods
)
# Create the table
cm <- c("StudyYear"     = "Year of study",
"PastAttacks_Country_5yr" = "Same country in previous 5 years",
"PastAttacks_West_5yr" = "All Western countries in previous 5 years",
"PastAttacks_Country_All" = "Same country in all previous years",
"PastAttacks_West_All" = "All Western countries in all previous years",
"FemaleP"       = "Percentage of Female Respondents",
"AgeMean"       = "Mean Age of Respondents",
"CasualtiesLess101"  = "Fatalities: $<$10",
"Casualties10to1001" = "Fatalities: 10–100",
"Casualties100plus1" = "Fatalities: $>$100",
"Exp1"          = "Randomized experiment",
"NatExp1"       = "Natural experiment",
"ProbSample1"   = "Probability sample",
"StudentPop"    = "Student sample",
"Outgroup"      = "Outgroup hostility",
"Rally"         = "Rally tendencies",
"US"            = "US study",
"StudyYear:FemaleP" = "Year of Study * Female share",
"StudyYear:AgeMean" = "Year of Study  * Mean age",
"StudyYear:StudentPop" = "Year of Study  * Student population",
"StudyYear:US" = "Year of Study  * US study",
"PastAttacks_Country_5yr:FemaleP" = "Past attacks * Female share",
"PastAttacks_Country_5yr:AgeMean" = "Past attacks * Mean age",
"PastAttacks_Country_5yr:StudentPop" = "Past attacks * Student population",
"PastAttacks_Country_5yr:US" = "Past attacks *  US study",
"PastAttacks_West_5yr:FemaleP" = "Past attacks * Female share",
"PastAttacks_West_5yr:AgeMean" = "Past attacks * Mean age",
"PastAttacks_West_5yr:StudentPop" = "Past attacks * Student population",
"PastAttacks_West_5yr:US" = "Past attacks *  US study",
"PastAttacks_Country_All:FemaleP" = "Past attacks * Female share",
"PastAttacks_Country_All:AgeMean" = "Past attacks * Mean age",
"PastAttacks_Country_All:StudentPop" = "Past attacks * Student population",
"PastAttacks_Country_All:US" = "Past attacks *  US study",
"PastAttacks_West_All:FemaleP" = "Past attacks * Female share",
"PastAttacks_West_All:AgeMean" = "Past attacks * Mean age",
"PastAttacks_West_All:StudentPop" = "Past attacks * Student population",
"PastAttacks_West_All:US" = "Past attacks *  US study",
"intrcpt"       = "Constant")
modelsummary(models,
coef_map = cm,
stars = c("*" = .05, "**" = .01, "***" = .001),
fmt = 3,
gof_omit = 'IC|Log|Adj|AIC|BIC|RMSE',
escape = FALSE,
output = "latex_tabular")
m2_mods
m2_past_1_mods
m2_past_2_mods
m2_past_3_mods
m2_past_4_mods
# Step 1: Create a named list of models
models <- list(
"(1)" = m2_mods,
"(2)" = m2_past_1_mods,
"(3)" = m2_past_2_mods,
"(4)" = m2_past_3_mods,
"(5)" = m2_past_4_mods
)
# Create the table
cm <- c("StudyYear"     = "Year of study",
"PastAttacks_Country_5yr" = "Same country in previous 5 years",
"PastAttacks_West_5yr" = "All Western countries in previous 5 years",
"PastAttacks_Country_All" = "Same country in all previous years",
"PastAttacks_West_All" = "All Western countries in all previous years",
"FemaleP"       = "Percentage of Female Respondents",
"AgeMean"       = "Mean Age of Respondents",
"CasualtiesLess101"  = "Fatalities: $<$10",
"Casualties10to1001" = "Fatalities: 10–100",
"Casualties100plus1" = "Fatalities: $>$100",
"Exp1"          = "Randomized experiment",
"NatExp1"       = "Natural experiment",
"ProbSample1"   = "Probability sample",
"StudentPop"    = "Student sample",
"Outgroup"      = "Outgroup hostility",
"Rally"         = "Rally tendencies",
"US"            = "US study",
"StudyYear:FemaleP" = "Year of Study * Female share",
"StudyYear:AgeMean" = "Year of Study  * Mean age",
"StudyYear:StudentPop" = "Year of Study  * Student population",
"StudyYear:US" = "Year of Study  * US study",
"PastAttacks_Country_5yr:FemaleP" = "Past attacks * Female share",
"PastAttacks_Country_5yr:AgeMean" = "Past attacks * Mean age",
"PastAttacks_Country_5yr:StudentPop" = "Past attacks * Student population",
"PastAttacks_Country_5yr:US" = "Past attacks *  US study",
"PastAttacks_West_5yr:FemaleP" = "Past attacks * Female share",
"PastAttacks_West_5yr:AgeMean" = "Past attacks * Mean age",
"PastAttacks_West_5yr:StudentPop" = "Past attacks * Student population",
"PastAttacks_West_5yr:US" = "Past attacks *  US study",
"PastAttacks_Country_All:FemaleP" = "Past attacks * Female share",
"PastAttacks_Country_All:AgeMean" = "Past attacks * Mean age",
"PastAttacks_Country_All:StudentPop" = "Past attacks * Student population",
"PastAttacks_Country_All:US" = "Past attacks *  US study",
"PastAttacks_West_All:FemaleP" = "Past attacks * Female share",
"PastAttacks_West_All:AgeMean" = "Past attacks * Mean age",
"PastAttacks_West_All:StudentPop" = "Past attacks * Student population",
"PastAttacks_West_All:US" = "Past attacks *  US study",
"intrcpt"       = "Constant")
modelsummary(models,
coef_map = cm,
stars = c("*" = .05, "**" = .01, "***" = .001),
fmt = 3,
gof_omit = 'IC|Log|Adj|AIC|BIC|RMSE',
escape = FALSE,
output = "latex_tabular")
"StudyYear"     = "Year of study",
# Create the table
cm <- c("intrcpt"       = "Constant",
"StudyYear"     = "Year of study",
"PastAttacks_Country_5yr" = "Same country in previous 5 years",
"PastAttacks_West_5yr" = "All Western countries in previous 5 years",
"PastAttacks_Country_All" = "Same country in all previous years",
"PastAttacks_West_All" = "All Western countries in all previous years",
"FemaleP"       = "Percentage of Female Respondents",
"AgeMean"       = "Mean Age of Respondents",
"CasualtiesLess101"  = "Fatalities: $<$10",
"Casualties10to1001" = "Fatalities: 10–100",
"Casualties100plus1" = "Fatalities: $>$100",
"Exp1"          = "Randomized experiment",
"NatExp1"       = "Natural experiment",
"ProbSample1"   = "Probability sample",
"StudentPop"    = "Student sample",
"Outgroup"      = "Outgroup hostility",
"Rally"         = "Rally tendencies",
"US"            = "US study",
"StudyYear:FemaleP" = "Year of Study * Female share",
"StudyYear:AgeMean" = "Year of Study  * Mean age",
"StudyYear:StudentPop" = "Year of Study  * Student population",
"StudyYear:US" = "Year of Study  * US study",
"PastAttacks_Country_5yr:FemaleP" = "Past attacks * Female share",
"PastAttacks_Country_5yr:AgeMean" = "Past attacks * Mean age",
"PastAttacks_Country_5yr:StudentPop" = "Past attacks * Student population",
"PastAttacks_Country_5yr:US" = "Past attacks *  US study",
"PastAttacks_West_5yr:FemaleP" = "Past attacks * Female share",
"PastAttacks_West_5yr:AgeMean" = "Past attacks * Mean age",
"PastAttacks_West_5yr:StudentPop" = "Past attacks * Student population",
"PastAttacks_West_5yr:US" = "Past attacks *  US study",
"PastAttacks_Country_All:FemaleP" = "Past attacks * Female share",
"PastAttacks_Country_All:AgeMean" = "Past attacks * Mean age",
"PastAttacks_Country_All:StudentPop" = "Past attacks * Student population",
"PastAttacks_Country_All:US" = "Past attacks *  US study",
"PastAttacks_West_All:FemaleP" = "Past attacks * Female share",
"PastAttacks_West_All:AgeMean" = "Past attacks * Mean age",
"PastAttacks_West_All:StudentPop" = "Past attacks * Student population",
"PastAttacks_West_All:US" = "Past attacks *  US study")
modelsummary(models,
coef_map = cm,
stars = c("*" = .05, "**" = .01, "***" = .001),
fmt = 3,
gof_omit = 'IC|Log|Adj|AIC|BIC|RMSE',
escape = FALSE,
output = "latex_tabular")
m2_mods
m2_past_1_mods
m2_past_2_mods
m2_past_3_mods
m2_past_4_mods
# Create the table
cm <- c(
"StudyYear"     = "Year of study",
"PastAttacks_Country_5yr" = "Same country in previous 5 years",
"PastAttacks_West_5yr" = "All Western countries in previous 5 years",
"PastAttacks_Country_All" = "Same country in all previous years",
"PastAttacks_West_All" = "All Western countries in all previous years",
"FemaleP"       = "Percentage of Female Respondents",
"AgeMean"       = "Mean Age of Respondents",
"CasualtiesLess101"  = "Fatalities: $<$10",
"Casualties10to1001" = "Fatalities: 10–100",
"Casualties100plus1" = "Fatalities: $>$100",
"Exp1"          = "Randomized experiment",
"NatExp1"       = "Natural experiment",
"ProbSample1"   = "Probability sample",
"StudentPop"    = "Student sample",
"Outgroup"      = "Outgroup hostility",
"Rally"         = "Rally tendencies",
"US"            = "US study",
"StudyYear:FemaleP" = "Year of Study * Female share",
"StudyYear:AgeMean" = "Year of Study  * Mean age",
"StudyYear:StudentPop" = "Year of Study  * Student population",
"StudyYear:US" = "Year of Study  * US study",
"PastAttacks_Country_5yr:FemaleP" = "Past attacks * Female share",
"PastAttacks_Country_5yr:AgeMean" = "Past attacks * Mean age",
"PastAttacks_Country_5yr:StudentPop" = "Past attacks * Student population",
"PastAttacks_Country_5yr:US" = "Past attacks *  US study",
"PastAttacks_West_5yr:FemaleP" = "Past attacks * Female share",
"PastAttacks_West_5yr:AgeMean" = "Past attacks * Mean age",
"PastAttacks_West_5yr:StudentPop" = "Past attacks * Student population",
"PastAttacks_West_5yr:US" = "Past attacks *  US study",
"PastAttacks_Country_All:FemaleP" = "Past attacks * Female share",
"PastAttacks_Country_All:AgeMean" = "Past attacks * Mean age",
"PastAttacks_Country_All:StudentPop" = "Past attacks * Student population",
"PastAttacks_Country_All:US" = "Past attacks *  US study",
"PastAttacks_West_All:FemaleP" = "Past attacks * Female share",
"PastAttacks_West_All:AgeMean" = "Past attacks * Mean age",
"PastAttacks_West_All:StudentPop" = "Past attacks * Student population",
"PastAttacks_West_All:US" = "Past attacks *  US study")
modelsummary(models,
coef_map = cm,
stars = c("*" = .05, "**" = .01, "***" = .001),
fmt = 3,
gof_omit = 'IC|Log|Adj|AIC|BIC|RMSE',
escape = FALSE,
output = "latex_tabular")
m2_mods
modelsummary(models)
modelsummary(models,
output = "latex_tabular"
,
coef_map = cm,
stars = c("*" = .05, "**" = .01, "***" = .001),
fmt = 3,
gof_omit = 'IC|Log|Adj|AIC|BIC|RMSE',
escape = FALSE,
output = "latex_tabular")
modelsummary(models,
output = "latex_tabular")
modelsummary(models,
coef_map = cm,
stars = c("*" = .05, "**" = .01, "***" = .001),
fmt = 3,
gof_omit = 'IC|Log|Adj|AIC|BIC|RMSE',
#escape = FALSE,
output = "latex_tabular")
#=============================================================================#
#
# PROJECT:        Does Islamist Terrorism Still Affect Political Attitudes?
# AUTHORS:        ** anonymized for review **
# CONTACT:        ** anonymized for review **
# LAST MODIFIED:  September 15, 2025
#
#=============================================================================#
#
# This R file contains the code used to replicate all results reported in the
###### main paper.
#
##### output:
# Table 1
# Table 2
# Figure 1
#
#=============================================================================#
rm(list=ls())
getwd()
# Install and load all necessary packages with the ipak function:
# i.e., check to see if packages are installed.
# Install them if they are not,
# then load them into the R session.
ipak <- function(pkg){  new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
if(length(new.pkg)) install.packages(new.pkg, dependencies = TRUE)
sapply(pkg, require, character.only = TRUE)
}
packages <- c("readxl", "metafor", "metaSEM", "tidyverse",
"ggplot2", "modelsummary", "stargazer")
ipak(packages)
# Data ------------------------------------------------------------------------
df <- readRDS("data/df.rds")
# delete 3 studies on effects of terrorism conducted outside Western democracies
# extra criterion 3
df <- df %>%
filter((ExactAttack_2 != "2002 Bali bombings" &  # attacks on western countries
ExactAttack_2 != "2008 Mumbai attacks" &  # attacks on western countries
ExactAttack_2 != "Gaza - Israel conflict") %>%
replace_na(TRUE))
# summary
summary(df)
# Main Analyses ----------------------------------------------------------------
## Average effect size --------------------------------------------------------
## Get estimates for...
# ... Overall sample
m0 <- rma.mv(d, var_d,
random = ~ 1 | ID_R/ID_ES_Unique,
data = df)
m0
## Average effect size over time ----------------------------------------------
df %>% count(is.na(StudyYear)) %>% mutate( prop = n / n_distinct(df))
df %>% filter(!is.na(StudyYear)) %>% distinct(ID_R) %>% nrow()
df <- df %>%
mutate(StudyYear = StudyYear - 2001)
df %>%
summarize(
min = min(StudyYear, na.rm = TRUE),
max = max(StudyYear, na.rm = TRUE)
) # study year: range
## Get estimates for...
# ... Model 1
m1 <- rma.mv(d, var_d,
mods = ~ StudyYear, # StudyYear as moderator
random = ~ 1 | ID_R/ID_ES_Unique, # three-level model
data = df)
m1
# ... Model 2
m2 <- rma.mv(d, var_d,
mods = ~ StudyYear + # StudyYear as moderator +
CasualtiesLess10 + Casualties10to100 + Casualties100plus +
Exp + NatExp +
ProbSample +
Outgroup + Rally +
US,
random = ~ 1 | ID_R/ID_ES_Unique, # three-level model
data = df)
m2
# Explore the correlation between Year of Study and being US-based
df$US <- as.numeric(df$US) - 1
mean(df$US[df$StudyYear + 2001 < 2005], na.rm = TRUE)
mean(df$US[df$StudyYear + 2001 >= 2005], na.rm = TRUE)
cor.test(df$StudyYear, df$US)
summary(df)
library('rcompanion')
cramerV(df$US, df$NineEleven, bias.correct = FALSE)
cor.test(as.numeric(df$US), as.numeric(df$NineEleven))
## Table (Table 1)
# Step 1: Create a named list of models
models <- list(
"Model 1" = m1,
"Model 2" = m2
)
# Create the table
cm <- c("StudyYear"     = "Year of study",
"CasualtiesLess101"  = "Fatalities: $<$10",
"Casualties10to1001" = "Fatalities: 10–100",
"Casualties100plus1" = "Fatalities: $>$100",
"Exp1"          = "Randomized experiment",
"NatExp1"       = "Natural experiment",
"ProbSample1"   = "Probability sample",
"Outgroup"      = "Outgroup hostility",
"Rally"         = "Rally tendencies",
"US1"           = "US dummy",
"intercept"     = "Constant")
modelsummary(models,
coef_map = cm,
stars = c("*" = .05, "**" = .01, "***" = .001),
fmt = 3,
gof_omit = 'IC|Log|Adj|AIC|BIC|RMSE',
escape = FALSE,
output = "latex_tabular")
## Effect of past attacks on effect sizes -------------------------------------
## Get estimates for...
# ... Model 2: Attacks in the same country during the 5 years prior to the study.
m2_past_1 <- rma.mv(d, var_d,
mods = ~ PastAttacks_Country_5yr +
CasualtiesLess10 + Casualties10to100 + Casualties100plus +
Exp + NatExp +
ProbSample +
Outgroup + Rally +
US,
random = ~ 1 | ID_R/ID_ES_Unique, # three-level model
data = df)
m2_past_1
# ... Model 2: Attacks in the West during the 5 years prior to the study.
m2_past_2 <- rma.mv(d, var_d,
mods = ~ PastAttacks_West_5yr +
CasualtiesLess10 + Casualties10to100 + Casualties100plus +
Exp + NatExp +
ProbSample +
Outgroup + Rally +
US,
random = ~ 1 | ID_R/ID_ES_Unique, # three-level model
data = df)
m2_past_2
# ... Model 2: Attacks in the same country, no time restriction.
m2_past_3 <- rma.mv(d, var_d,
mods = ~ PastAttacks_Country_All +
CasualtiesLess10 + Casualties10to100 + Casualties100plus +
Exp + NatExp +
ProbSample +
Outgroup + Rally +
US,
random = ~ 1 | ID_R/ID_ES_Unique, # three-level model
data = df)
m2_past_3
# ... Model 2: Attacks in the West, no time restriction.
m2_past_4 <- rma.mv(d, var_d,
mods = ~ PastAttacks_West_All +
CasualtiesLess10 + Casualties10to100 + Casualties100plus +
Exp + NatExp +
ProbSample +
Outgroup + Rally +
US,
random = ~ 1 | ID_R/ID_ES_Unique, # three-level model
data = df)
m2_past_4
## Table (Table 1)
# Step 1: Create a named list of models
models <- list(
"Model 1" = m2_past_1,
"Model 2" = m2_past_2,
"Model 3" = m2_past_3,
"Model 4" = m2_past_4
)
# Create the table
cm <- c("PastAttacks_Country_5yr" = "Number of previous Islamist attacks (same country, 5 years)",
"PastAttacks_West_5yr" = "Number of previous Islamist attacks (all Western countries, 5 years)",
"PastAttacks_Country_All" = "Number of previous Islamist attacks (same country, all years)",
"PastAttacks_West_All" = "Number of previous Islamist attacks (all Western countries, all years)",
"intercept"     = "Constant")
modelsummary(models,
coef_map = cm,
stars = c("*" = .05, "**" = .01, "***" = .001),
fmt = 3,
gof_omit = 'IC|Log|Adj|AIC|BIC|RMSE',
escape = FALSE,
output = "latex_tabular")
## Average effect size by attack ----------------------------------------------
df_attacks <- df %>%
filter(Attack == 1, # reference to/study real attacks
ExactAttack_2 != "2014 Jewish Museum of Belgium shooting",
# only 1 observation: no Meta-Analysis possible
ExactAttack_2 != "2015 San Bernardino",
# only 1 observation: no Meta-Analysis possible
ExactAttack_2 != "Hypothetical attack", # no hypothetical attacks
ExactAttack_2 != "Other attack or combination", # no combinations
ExactAttack_2 != "Unspecified attack", # no unspecified attacks
ExactAttack_2 != "2002 Bali bombings", # attacks in western countries
ExactAttack_2 != "2008 Mumbai attacks", # attacks in western countries
ExactAttack_2 != "Gaza - Israel conflict") # attacks on western countries
df_attacks %>% distinct(ExactAttack_2) %>% nrow()
unique(df_attacks$ExactAttack_2)
df_attacks %>% distinct(ID_ES_Unique) %>% nrow()
df_attacks %>% distinct(ID_R) %>% nrow()
## Get estimates for...
# ... Model 0, with accounting for attack-clustering
df_attacks$ExactAttack <- as.factor(df_attacks$ExactAttack_2)
m0_attacks <- rma.mv(d, var_d,
random = ~ 1 | ExactAttack/ID_R/ID_ES_Unique, # four-level model
data = df_attacks)
m0_attacks
